package com.example.hello.client.NavWidget;

import com.example.hello.BootstrapNavWidget;
import com.github.gwtbootstrap.client.ui.constants.IconPosition;
import com.github.gwtbootstrap.client.ui.constants.IconSize;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapNavWidget.class)
public class BootstrapNavWidgetConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapNavWidget.class);
    }

    @Override
    public BootstrapNavWidgetState getState() {
        return (BootstrapNavWidgetState) super.getState();
    }

    @Override
    public VBootstrapNavWidget getWidget() {
        return (VBootstrapNavWidget) super.getWidget();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapNavWidgetState state = getState();

        VBootstrapNavWidget navWidget = getWidget();

        navWidget.setActive(state.isActive());
        navWidget.setBaseIcon(IconType.valueOf(state.getBaseIcon()));
        navWidget.setCustomIconStyle(state.getCustomIconSet());
        navWidget.setDisabled(state.isDisabled());
        navWidget.setHref(state.getHref());
        navWidget.setIcon(IconType.valueOf(state.getIcon()));
        navWidget.setIconPosition(IconPosition.valueOf(state.getIconPosition()));
        navWidget.setIconSize(IconSize.valueOf(state.getIconSize()));
        navWidget.setName(state.getName());
        navWidget.setTarget(state.getTarget());
        navWidget.setText(state.getText());
    }

}